package com.maven.front.service.eduQuestions;


import com.maven.front.bean.EduQuestions;
import com.maven.front.bean.EduUser;
import com.maven.front.dto.EduQuestionsDto;
import com.maven.front.mapper.EduQuestionsMapper;
import com.maven.front.mapper.EduUserMapper;
import com.maven.front.mapper.SysUserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class EduQuestionsService {

    @Resource
    private EduQuestionsMapper eduQuestionsMapper;
    @Resource
    private EduUserMapper eduUserMapper;


        //查询
    public List<EduQuestionsDto> listAll(EduQuestions eduQuestions){
        List<EduQuestionsDto> listeduQuestionsDto=new ArrayList<>();
        List<EduQuestions> listeduQuestions=eduQuestionsMapper.select(eduQuestions);
        for (int i=0;i<listeduQuestions.size();i++){
            String email=eduUserMapper.selectByPrimaryKey(listeduQuestions.get(i).getCusId()).getEmail();
            EduQuestionsDto eduQuestionsDto=new EduQuestionsDto();
            //  将父类数据复制给子类数据
            BeanUtils.copyProperties(listeduQuestions.get(i),eduQuestionsDto);
            //将获取的名称赋值给子类的新属性(name)
            eduQuestionsDto.setEmail(email);
            listeduQuestionsDto.add(eduQuestionsDto);
        }
        if(listeduQuestionsDto!=null){
            return listeduQuestionsDto;
        }else{
            return null;
        }

    }


    //删除
    public int delete(Integer id){
        int a=eduQuestionsMapper.deleteByPrimaryKey(id);
        if (a==1){
            return 1;
        }else {
            return 0;
        }
    }

    //修改
    public int update1(EduQuestions eduQuestions){
        return eduQuestionsMapper.update1(eduQuestions);

    }

    //根据id查看
    public EduQuestions getid(Integer id){
        return eduQuestionsMapper.selectByPrimaryKey1(id);
    }


}
